#ifndef PLAYLISTENTRY_H
#define PLAYLISTENTRY_H

#include <QFileInfo>
#include <QDateTime>

class AudioFile;
class Playlist;

class PlaylistEntry : public QObject
{
    Q_OBJECT
    Q_DISABLE_COPY(PlaylistEntry)

public:
    PlaylistEntry(Playlist *i_pPlaylist, AudioFile *i_pAudioFile,
                  const QString& i_filepath,
                  const QString& i_title = QString(),
                  const QString& i_artist = QString(),
                  const QString& i_album = QString(),
                  const QString& i_genre = QString(),
                  const QString& i_track = QString(),
                  const QString& i_year = QString(),
                  const QString& i_date1 = QDateTime::currentDateTime().toString(DATE_TIME_FORMAT),
                  const QString& i_date2 = QDateTime::currentDateTime().toString(DATE_TIME_FORMAT),
                  const QString& i_empty1 = QString(),
                  const QString& i_empty2 = QString());

    virtual ~PlaylistEntry();

    inline const QString& filepath() const {return m_filepath;}
    inline const QString& filename() const {return m_filename;}
    inline const QString& title() const {return m_title;}
    inline const QString& artist() const {return m_artist;}
    inline const QString& album() const {return m_album;}
    inline const QString& genre() const {return m_genre;}
    inline uint track() const {return m_track;}
    inline uint year() const {return m_year;}
    inline const QString& date1() const {return m_date1;}
    inline const QString& date2() const {return m_date2;}
    inline uint empty1() const {return m_empty1;}
    inline uint empty2() const {return m_empty2;}

    inline const AudioFile* audioFile() const {return m_pAudioFile;}
    inline const Playlist* playlist() const {return m_pPlaylist;}
    inline bool isMissing() const {return m_pAudioFile == NULL;}
    inline bool isDuplicate() const {return false;}

    bool isCompleteAndValid() const {return m_completeAndValid;}

    void setFilePath(const QString& i_path);
    void setAudioFile(AudioFile* i_pAudioFile);
    void removeAudioFile();
    void refreshTags();

    void setTitle(const QString& i_value);
    void setArtist(const QString& i_value);
    void setAlbum(const QString& i_value);
    void setGenre(const QString& i_value);
    void setTrack(const QString& i_value, bool i_emit = true);
    void setYear(const QString& i_value, bool i_emit = true);

    static inline bool lessThan(const PlaylistEntry* pLeft, const PlaylistEntry* pRight)
    {return QString::localeAwareCompare(pLeft->m_filename, pRight->m_filename) < 0;}

signals:
    void dataChanged();
    void completeStateChanged(bool);

private:
    void checkCompleteAndValid();

private:
    QString m_filepath;
    QString m_filename;
    AudioFile* m_pAudioFile;
    Playlist* m_pPlaylist;

    bool m_completeAndValid;

    QString m_title;
    QString m_artist;
    QString m_album;
    QString m_genre;
    uint m_track;
    uint m_year;
    QString m_date1;
    QString m_date2;
    uint m_empty1;
    uint m_empty2;

    static const QString DATE_TIME_FORMAT;
};

#endif // PLAYLISTENTRY_H
